/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sahd.broker.server;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

/**
 *
 * @author Romms
 */
public class ServerMachine implements Serializable{

    public ServerMachine(String clientMachiengIpAddress, String clientMachineMacAddress) {
        this.clientMachiengIpAddress = clientMachiengIpAddress;
        this.clientMachineMacAddress = clientMachineMacAddress;
    }
    private InetAddress localHost;
    private String clientMachiengIpAddress;
    private String clientMachineMacAddress;

    public ServerMachine() throws UnknownHostException, SocketException{
        localHost= InetAddress.getLocalHost();
        this.updateServerMachiengIpAddress();
        this.updateServerMachineMacAddress();

    }

    public String getServerMchingeIpAddres(){
        return this.clientMachiengIpAddress;
    }

    public String getServerMchingeMacAddres(){
        return this.clientMachineMacAddress;
    }


    private void updateServerMachiengIpAddress() throws UnknownHostException {
        localHost= InetAddress.getLocalHost();
        this.clientMachiengIpAddress= localHost.getHostAddress();
    }

    private void updateServerMachineMacAddress() throws SocketException {
        this.clientMachineMacAddress="";
        NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
        byte[] mac = networkInterface.getHardwareAddress();
        //for (int i = 0; i < mac.length; i++) {
         //   this.clientMachineMacAddress+=System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "").toString();
        //}
    }
}
